package com.zatech.cgnci.project.base.enums;

/**
 * 系统基础响应码
 *
 * @author Yingdf
 * @since 2024-4-10
 */
public enum ResponseCodeEnum implements ResponseCodeEnumSupport {

    // 公共错误状态码 (1000xx)
    // ----------------------------------------------------------------------
    UNKNOWN_ERROR("100001", "未知错误，请稍后重试"),
    NETWORK_ERROR("100002", "网络错误，请稍后重试"),
    SERVICE_ERROR("100003", "服务错误，请稍后重试"),
    THIRD_PARTY_SERVICE_ERROR("100004", "第三方服务错误，请稍后重试"),
    DUPLICATE_KEY_ERROR("100005", "数据重复异常，请联系管理员"),
    MULTIPART_ERROR("100006", "文件上传错误，请联系管理员"),
    BAD_SQL_GRAMMAR_ERROR("100007", "SQL语法错误，请联系管理员"),
    SQL_ERROR("100008", "数据库操作错误，请联系管理员"),
    REMOTE_ERROR("100009", "远程调用错误，请联系管理员"),

    PARAMS_ILLEGAL("300007", "参数非法"),
    ACCESS_DENIED("300008", "权限不足"),


    // HTTP请求 错误状态码(1002xx)
    HTTP_REQUEST_SUCCESS("200", "请求成功"),
    HTTP_REQUEST_LOGIN_ERROR("401", "登录失败"),

    HTTP_REQUEST_SERVICE_ERROR("500", "服务错误,请稍后重试"),
    ;

    private final String code;
    private final String msg;

    ResponseCodeEnum(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getMsg() {
        return msg;
    }

    /**
     * 根据 CODE 获取 Status 枚举类.
     *
     * @param code Status Code
     * @return Status
     */
    public static ResponseCodeEnum fromCode(String code) {
        ResponseCodeEnum[] statuses = ResponseCodeEnum.values();
        for (ResponseCodeEnum status : statuses) {
            if (status.getCode().equals(code)) {
                return status;
            }
        }
        return null;
    }

}
